package com.baseDemo.web.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.annotations.GenericGenerator;
import org.quartz.Job;
import org.springframework.format.annotation.DateTimeFormat;

import com.share.date.JsonDateSerializer;
import com.share.quartz.service.IQuartzJobEntity;
/**
 * 定时任务 数据库持久化类 
 * @author xianwei
 *
 */
@Entity
@Table(name = "t_QuartzEntity")
public class QuartzEntity implements IQuartzJobEntity{
	
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
	@Column(length = 50)
	private String id;
	//需和配置文件中bean的id保持一致 
	@Column(length = 50)
	private String jobName;
	@Column(length = 50)
	private String groupName;
	@Column(length = 50)
	private String clazzName;
	@Column(length = 50)
	private String cronExpression;
	@Column(length = 50)
	private String cronMethod;
	@Column(length = 50)
	private String status="停止";
	@Temporal(TemporalType.TIMESTAMP)
	@Column(length = 25)
	private Date createDate = new Date();
	@Column(length = 100)
	private String description;
	/**
	 * @return the cronMethod
	 */
	public String getCronMethod() {
		return cronMethod;
	}
	/**
	 * @param cronMethod the cronMethod to set
	 */
	public void setCronMethod(String cronMethod) {
		if(cronMethod!=null&&!"".equals(cronMethod)){
			this.cronMethod = cronMethod;
		}else{
			this.cronMethod = "execute";
		}
	}
	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
	/**
	 * @return the jobName
	 */
	public String getJobName() {
		return jobName;
	}
	/**
	 * @param jobName the jobName to set
	 */
	public void setJobName(String jobName) {
		this.jobName = jobName;
	}
	/**
	 * @return the groupName
	 */
	public String getGroupName() {
		return groupName;
	}
	/**
	 * @param groupName the groupName to set
	 */
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}
	/**
	 * @return the clazzName
	 */
	public String getClazzName() {
		return clazzName;
	}
	/**
	 * @param clazzName the clazzName to set
	 */
	public void setClazzName(String clazzName) {
		this.clazzName = clazzName;
	}
	/**
	 * @return the cronExpression
	 */
	public String getCronExpression() {
		return cronExpression;
	}
	/**
	 * @param cronExpression the cronExpression to set
	 */
	public void setCronExpression(String cronExpression) {
		this.cronExpression = cronExpression;
	}
	private static final long serialVersionUID = 4457127588255186152L;


	@Override
	public String getTriggerName() {
		// TODO Auto-generated method stub
		return this.jobName+"Trigger";
	}
	@Override
	public Class<? extends Job> getClazz() throws InstantiationException,
			IllegalAccessException, ClassNotFoundException {
		return null;
	}
	@Override
	public String toString() {
		return getJobName()+"+"+getGroupName()+"+"+getClazzName()+"+"+getCronMethod()+"+"+getCronExpression();
	}
	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}
	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}
	/**
	 * @return the createDate
	 */
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")  
	@JsonSerialize(using=JsonDateSerializer.class)
	public Date getCreateDate() {
		return createDate;
	}
	/**
	 * @param createDate the createDate to set
	 */
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
}
